﻿package mortal.game.view.rebate.shop.item
{
    import Message.Game.*;
    import Message.Public.*;
    import com.mui.controls.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.rebate.item.*;
    import mortal.mvc.core.*;

    public class RebateShopCell extends GSprite
    {
        protected var _bg:GImageBitmap;
        protected var _nameTxt:GTextFiled;
        protected var _numTxt:GTextFiled;
        protected var _newPrice:GTextFiled;
        protected var _oldPrice:GTextFiled;
        protected var _money1:GBitmap;
        protected var _money2:GBitmap;
        protected var _delLine:GBitmap;
        protected var _buyBtn:GLoadingButton;
        protected var _item:RebateItem;
        private var _baseInfo:Object;
        private var _shopInfo:SOnSellItem;
        private var _rema:int = -1;
        private var _playerInfo:SOnSellItemPlayer;

        public function RebateShopCell()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._bg = UIFactory.gImageBitmap(ImagesConst.RebateShopCellBg, 0, 0, this);
            this._nameTxt = UIFactory.gTextField("", -2, 6, 212, 25, this, GlobalStyle.textFormatAnjin.setSize(13).center());
            this._numTxt = UIFactory.gTextField("", 7, 123, 200, 25, this, GlobalStyle.textFormatLv.setSize(14).setBold(true));
            this._newPrice = UIFactory.gTextField("", 92, 81, 100, 25, this, GlobalStyle.textFormatDanLan.setSize(14));
            this._oldPrice = UIFactory.gTextField("", 92, 51, 100, 25, this, GlobalStyle.textFormatlan.setSize(14));
            this._money1 = UIFactory.gBitmap(ImagesConst.Yuanbao, 177, 53, this);
            this._money2 = UIFactory.gBitmap(ImagesConst.Yuanbao, 176, 83, this);
            this._delLine = UIFactory.gBitmap(ImagesConst.deleteLine, 137, 61, this);
            this._buyBtn = UIFactory.gLoadingButton(ImagesConst.LineOffCopyCellBtn_upSkin, 150, 122, 53, 24, this);
            this._buyBtn.label = "" + Language.getString(71908);
            this._item = UIFactory.getUICompoment(RebateItem, 14, 45, this);
            var _loc_1:Boolean = false;
            this._numTxt.mouseEnabled = false;
            this._numTxt.selectable = _loc_1;
            this._buyBtn.configEventListener(MouseEvent.CLICK, this.onBugHd);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._bg.dispose(param1);
            this._nameTxt.dispose(param1);
            this._numTxt.dispose(param1);
            this._newPrice.dispose(param1);
            this._oldPrice.dispose(param1);
            this._money1.dispose(param1);
            this._money2.dispose(param1);
            this._delLine.dispose(param1);
            this._buyBtn.dispose(param1);
            this._bg = null;
            this._nameTxt = null;
            this._numTxt = null;
            this._newPrice = null;
            this._oldPrice = null;
            this._money1 = null;
            this._money2 = null;
            this._delLine = null;
            this._buyBtn = null;
            this._rema = -1;
            return;
        }// end function

        public function updateBaseInfo(param1:Object) : void
        {
            this._baseInfo = param1;
            if (this._baseInfo == null)
            {
                return;
            }
            var _loc_2:* = new SPlayerItem();
            _loc_2.itemCode = this._baseInfo.itemCode;
            this._item.updateInfo(_loc_2);
            this._numTxt.text = Language.getStringByParam(71909, this._baseInfo.buyLimit);
            this._oldPrice.text = Language.getString(71910) + this._baseInfo.price;
            this._newPrice.text = Language.getString(71911) + this._baseInfo.totalAmountEx;
            var _loc_3:* = ItemConfig.instance.getConfig(this._baseInfo.itemCode);
            if (this._nameTxt)
            {
                this._nameTxt.text = "" + _loc_3.name;
            }
            return;
        }// end function

        public function updateCellRemain(param1:SOnSellItem) : void
        {
            this._shopInfo = param1;
            if (this._shopInfo == null)
            {
                return;
            }
            this._newPrice.text = Language.getString(71911) + this._shopInfo.discount;
            if (!this._baseInfo.buyLimit)
            {
                this._numTxt.text = Language.getString(71912);
            }
            else if (this._rema == -1)
            {
                this._numTxt.text = Language.getStringByParam(71913, this._baseInfo.buyLimit, this._shopInfo.leftAmount);
            }
            else
            {
                this._numTxt.text = Language.getStringByParam(71914, this._rema, this._shopInfo.leftAmount);
            }
            return;
        }// end function

        public function updatePlayerInfo(param1:SOnSellItemPlayer) : void
        {
            this._playerInfo = param1;
            if (this._playerInfo == null)
            {
                return;
            }
            if (!this._baseInfo.buyLimit)
            {
                this._numTxt.text = "" + Language.getString(71912);
                return;
            }
            this._rema = this._baseInfo.buyLimit - this._playerInfo.amount;
            if (this._shopInfo)
            {
                this._numTxt.text = Language.getStringByParam(71915, this._rema, this._shopInfo.leftAmount);
            }
            else
            {
                this._numTxt.text = Language.getStringByParam(71916, this._rema, this._baseInfo.totalAmount);
            }
            return;
        }// end function

        protected function onBugHd(event:MouseEvent) : void
        {
            var _loc_2:int = 0;
            if (this._playerInfo != null)
            {
                _loc_2 = this._playerInfo.amount;
            }
            if (this._baseInfo.buyLimit)
            {
                if (this._baseInfo.buyLimit - _loc_2 < 0)
                {
                    MsgManager.showRollTipsMsg("" + Language.getString(71917));
                    return;
                }
            }
            if (this._shopInfo && this._shopInfo.leftAmount == 0)
            {
                MsgManager.showRollTipsMsg("" + Language.getString(71918));
                return;
            }
            if (this._playerInfo)
            {
                if (this._baseInfo.buyLimit && this._baseInfo.buyLimit - this._playerInfo.amount <= 0)
                {
                    MsgManager.showRollTipsMsg("" + Language.getString(71919));
                    return;
                }
            }
            var _loc_3:Object = {};
            _loc_3.itemCode = this._baseInfo.itemCode;
            _loc_3.item = this._item;
            Dispatcher.dispatchEvent(new DataEvent(EventName.RebateShopBuyItem, _loc_3));
            return;
        }// end function

    }
}
